package jiyun.com.yiyanmeng;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.Timer;
import java.util.TimerTask;

import base.BaseActivity;
import bean.GuangGaoBean;
import presenter.GuangGaoPresenter;
import utils.ToastUtil;
import view.GuangGaoView;

public class GuangGaoActivity extends BaseActivity<GuangGaoView, GuangGaoPresenter>implements GuangGaoView {


    private ImageView img;

    @Override
    public void showToast(String msg) {
        ToastUtil.show(this,msg);

    }

    @Override
    protected void initData() {
        mPresenter.requestGuangGao();

    }

    @Override
    protected void setListener() {

    }

    @Override
    protected void initView() {
        img = findViewById(R.id.guanggao_img);



    }

    @Override
    protected GuangGaoPresenter createPresenter() {
        return new GuangGaoPresenter();
    }

    @Override
    protected int bindLayoutId() {
        return R.layout.activity_guang_gao;
    }

    @Override
    public void onSuccess(final GuangGaoBean data) {
        String pic = data.getPic();
        Log.i("tag", "onSuccess: "+pic);
        img.setImageResource(R.drawable.guanggao);
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(GuangGaoActivity.this, WebActivity.class);
                intent.putExtra("url",data.getUrl());
                startActivity(intent);


            }
        });
        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                Intent intent = new Intent(GuangGaoActivity.this, LoginActivity.class);
                startActivity(intent);
                finish();

            }
        };
        timer.schedule(timerTask,1000);

    }

    @Override
    public void onFail(String error) {
        Intent intent = new Intent(GuangGaoActivity.this, LoginActivity.class);
        startActivity(intent);
        finish();

    }


}
